home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / prog / basic / ltest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  1.8 KB  |  100 lines

  1. #include <LEDA/basic.h>
  2. #include <LEDA/list.h>
  3.  
  4.  
  5. int ord(const int& x) { return x%1000; }
  6.  
  7. int main () 
  8. {
  9.   list<int>     L;
  10.   list<int>     L1;
  11.   list<double>   L2;
  12.  
  13.   int i;
  14.  
  15.   int N = read_int("Number of list entries: "); 
  16.  
  17.   float T = used_time();
  18.  
  19.   cout << "allocating    ";
  20.   cout.flush();
  21.   for (i = 0; i < N; i++) L.append(random(1,10000));
  22.   cout << string("  %5.3f sec",used_time(T));
  23.   newline;
  24.  
  25.  
  26.   cout << "reversing     ";
  27.   cout.flush();
  28.   while (!L.empty()) L1.push(L.pop());
  29.   cout << string("  %5.3f sec",used_time(T));
  30.   newline;
  31.  
  32.   cout << "assignment    ";
  33.   cout.flush();
  34.   L = L1;
  35.   cout << string("  %5.3f sec",used_time(T));
  36.   newline;
  37.  
  38.   cout << "sorting(int)  ";
  39.   cout.flush();
  40.   L.sort();
  41.   cout << string("  %5.3f sec",used_time(T));
  42.   newline;
  43.  
  44.   cout << "sorting again ";
  45.   cout.flush();
  46.   L.sort();
  47.   cout << string("  %5.3f sec",used_time(T));
  48.   newline;
  49.  
  50.  
  51.   cout << "iteration     ";
  52.   cout.flush();
  53.   forall(i,L) {}
  54.   cout << string("  %5.3f sec",used_time(T));
  55.   newline;
  56.  
  57.   forall(i,L) L2.append(i);
  58.  
  59.   cout << "sorting(double)";
  60.   cout.flush();
  61.   L2.sort();
  62.   cout << string("  %5.3f sec",used_time(T));
  63.   newline;
  64.  
  65.  
  66.   cout << "sorting again ";
  67.   cout.flush();
  68.   L2.sort();
  69.   cout << string("  %5.3f sec",used_time(T));
  70.   newline;
  71.  
  72.  
  73.  
  74.   cout << "test sorting  ";
  75.   cout.flush();
  76.   forall(i,L)
  77.   { double f = L2.pop();
  78.     if (i != f)  cout << string("%d  != %f\n",i,f);
  79.    }
  80.   cout << string("  %5.3f sec",used_time(T));
  81.   newline;
  82.   
  83.   cout << "bucket sort   ";
  84.   cout.flush();
  85.   L.bucket_sort(0,1000,ord);
  86.   cout << string("  %5.3f sec",used_time(T));
  87.   newline;
  88.  
  89.   cout << "clear         ";
  90.   cout.flush();
  91.   L.clear();
  92.   cout << string("  %5.3f sec",used_time(T));
  93.   newline;
  94.  
  95.   newline;
  96.   cout << "used memory = " << used_memory()/1024.0 << " kb\n";
  97.  
  98.   return 0;
  99. }
  100.